package com.ruoyi.web.controller.system;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.Student;
import com.ruoyi.system.domain.SysRecord;
import com.ruoyi.system.service.ISysRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 参数配置 信息操作处理
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/android")
public class AndroidController extends BaseController
{
    @Autowired
    private ISysRecordService sysRecordService;

    @RequestMapping(value = "/info",method = RequestMethod.GET)
    public String getInfo(){
        return "1234";
    }
//    @RequestMapping(value = "records")
//    public List<SysRecord> addMrecords(@RequestParam("record") String str){
//        List<SysRecord> studentList = (List<SysRecord>) JSONArray.parseArray(str,SysRecord.class);
//        if(null != studentList){
//            for(int i = 0;i<studentList.size();i++){
//               // insertInto(studentList.get(i).getName(),studentList.get(i).getAge());
//            }
//        }
//        return null;
//    }
    @RequestMapping(value = "/record",method = RequestMethod.POST)
    public AjaxResult addMoreStudent(@RequestParam("record") String str){
        SysRecord sysRecord= JSONObject.parseObject(str,SysRecord.class);
        return toAjax(sysRecordService.insertSysRecordfromeDev(sysRecord));
    }
//    /**
//     * 批量添加student到mysql数据库
//     * */
//    private void addMoreStudents(List<Student> studentList){
//        String studentsStr = JSON.toJSONString(studentList);
//        OkHttpClient mOkHttpClient = new OkHttpClient();
//        FormEncodingBuilder builder = new FormEncodingBuilder();
//        builder.add("students",studentsStr);
//        final Request request = new Request.Builder()
//                .url(AppConfig.ADD_MORE_STUDENTS)
//                .post(builder.build())
//                .build();
//        Call call = mOkHttpClient.newCall(request);
//        call.enqueue(new Callback() {
//            @Override
//            public void onFailure(Request request, IOException e) {
//
//            }
//
//            @Override
//            public void onResponse(Response response) throws IOException {
//                String responseStr = response.body().string();
//                List<Student> studentEntities = new ArrayList<>();
//                studentEntities = com.alibaba.fastjson.JSONArray.parseArray(responseStr,Student.class);
//                Message msg = mHandler.obtainMessage();
//                msg.obj = studentEntities;
//                mHandler.sendMessage(msg);
//            }
//        });
//    }
}
